﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace School.WebPages.TeacheManage
{
    public partial class SubjectList : System.Web.UI.Page
    {
        TechnologySchoolEntities db = new TechnologySchoolEntities();
        protected string parentCategoryStr = string.Empty;
        protected string categoryStr = string.Empty;
        protected string categoryName = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            parentCategoryStr = Request.QueryString["parentCategory"];
            categoryStr = Request.QueryString["categories"];
            byte category = byte.Parse(categoryStr);
            categoryName = db.SubMenu.FirstOrDefault(s => s.Categories == category).Name;

            if (!Page.IsPostBack)
            {
                AspNetPager1.RecordCount = db.Article.Where(a => a.SubMenu.Categories == category && a.IsChecked == 1 && a.IsEnabled == true).Count();
                BindData();
            }
        }

        private void BindData()
        {
            rep_item.DataSource = DAL.PagerHelper.GetPagerData("Article", "ArticleID,Title,UpdateTime", "UpdateTime",
                AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex, "Categories=" + categoryStr + " and IsChecked=1 and IsEnabled=1");
            rep_item.DataBind();
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindData();
        }
    }
}
